package com.emmy.walnut.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.emmy.walnut.R;
import com.emmy.walnut.model.Label;
import com.emmy.walnut.view.SingleClassDetailActivity;

import java.util.ArrayList;
import java.util.List;

public class ClassAdapter extends RecyclerView.Adapter<ClassAdapter.ViewHolder> {

    private Context mContext;
    private List<Label> mList = new ArrayList<>();

    public ClassAdapter(Context context, List<Label> list){
        mContext = context;
        if (list!=null) {
            mList = list;
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_activity,parent,
                false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.textView.setText(mList.get(position).getLabelName());
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        TextView textView;
        ViewHolder(View view){
            super(view);
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, SingleClassDetailActivity.class);
                    intent.putExtra("index", getAdapterPosition());
                    mContext.startActivity(intent);
                }
            });
            textView = view.findViewById(R.id.activity_item);
        }
    }
}
